import Vue from 'vue'
import Router from 'vue-router'

Vue.use(Router)

// 静态路由模块（即所有用户都可以访问的页面）
import home from './modules/home'
import login from './modules/login'
import notFound from './modules/not_found'

export const constantRoutes = [
  home,
  login,
  notFound
]

// 动态路由模块（即所有用户都可以访问的页面）
import word from './modules/word'
import zh_speech from './modules/zh_speech'

export const variableRoutes = [
  word,
  zh_speech
]

const createRouter = () => new Router({
  // mode: 'history', // require service support
  scrollBehavior: () => ({ y: 0 }),
  routes: [
    {
      path: '/',
      redirect: '/home'
    },
    ...constantRoutes
  ]
})

const router = createRouter()

// Detail see: https://github.com/vuejs/vue-router/issues/1234#issuecomment-357941465
export function resetRouter() {
  const newRouter = createRouter()
  router.matcher = newRouter.matcher // reset router
}

export default router
